#!/usr/bin/env python
# -*- coding: utf-8 -*-
# 文件名称: __init__.py
# 文件保存路径: backend/api/miniprogram/__init__.py
"""
微信小程序专用API模块
基于现有系统架构，为小程序提供专用接口
"""

from flask import Blueprint

# 创建小程序专用蓝图
miniprogram_bp = Blueprint('miniprogram', __name__, url_prefix='/api/miniprogram')

_MINIPROGRAM_MODULES = [
    'auth_api',
    'user_api',
    'intervention_api',
    'query_api',
    'social_api',
    'notification_api',
    'communication_api',
    'upload_api',
    'privacy_api',  # 隐私设置API
    # 聚合/页面级接口：保留有价值的聚合（records / security-status / export），已移除 followup 聚合
    'aggregated_api',
    'followup_api',
    'feedback_api'
]

def _import_modules_with_logging():
    """静默导入小程序模块"""
    from importlib import import_module
    base_pkg = __name__  # backend.api.miniprogram
    for mod in _MINIPROGRAM_MODULES:
        try:
            import_module(f'{base_pkg}.{mod}')
        except Exception as e:
            # 仅在出错时输出，便于调试
            print(f'[miniprogram][import][FAIL] {mod} -> {e.__class__.__name__}: {e}')
            import traceback; traceback.print_exc()

# 注册蓝图路由
def init_miniprogram_api(app):
    """初始化小程序API模块"""
    _import_modules_with_logging()
    app.register_blueprint(miniprogram_bp)